﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WITM.DAL;

namespace WITM.BLL
{
    public class SpendingEntryBL
    {
        private IUnitOfWork unitOfWork;

        public SpendingEntryBL(IUnitOfWork unitOfWork)
        {
            this.unitOfWork = unitOfWork;
        }

        public IEnumerable<SpendingEntries> GetAll()
        {
            return unitOfWork.SpendingEntryRepository.GetAll();
        }

        public IEnumerable<SpendingEntries> GetAllPerDate(int userID, DateTime date)
        {
            return unitOfWork.SpendingEntryRepository.Find(e => 
                e.SpendingItems.SpendingCategories.Users.UserID == userID
                && e.Date == date);
        }

        public void Add(SpendingEntries entry)
        {
            unitOfWork.SpendingEntryRepository.Add(entry);
            unitOfWork.Commit();
        }

        public List<SpendingSum> GetTotalCategories(int userID)
        {
            return GetTotalCategories(userID, null, null);
        }

        public List<SpendingSum> GetTotalCategories(int userID, DateTime? startDate, DateTime? endDate)
        {
            return unitOfWork.SpendingEntryRepository.GetTotalCategories(userID, startDate, endDate);
        }

        public List<SpendingSum> GetTotalItems(int userID)
        {
            return GetTotalItems(userID, null, null);
        }

        public List<SpendingSum> GetTotalItems(int userID, DateTime? startDate, DateTime? endDate)
        {
            return unitOfWork.SpendingEntryRepository.GetTotalItems(userID, startDate, endDate);
        }

        public List<SpendingSum> GetTotalDays(int userID)
        {
            return GetTotalDays(userID, null, null);
        }

        public List<SpendingSum> GetTotalDays(int userID, DateTime? startDate, DateTime? endDate)
        {
            return unitOfWork.SpendingEntryRepository.GetTotalDays(userID, startDate, endDate);
        }


    }
}
